package com.shawn.datastructure.stack;

public class StackBasedOnArray {

	private int[] data;
	private int length;
	private int size;

	public StackBasedOnArray(int length) {
		this.data = new int[length];
		this.length = length;
		this.size = 0;
	}

	public void push(int value) {
		if (size == length) {
			return;
		}
		data[size] = value;
		size++;
	}

	public int pop() {
		if (size == 0) {
			return -1;
		}
		int result = data[size - 1];
		size--;
		return result;
	}

	public int peek() {
		if (size != 0) {
			return data[size - 1];
		} else {
			System.out.println("The stack is empty, cant peek");
			return -1;
		}
	}

}
